package com.luguz.service.impl;

import com.alibaba.fastjson.JSON;
import com.luguz.common.HotSearch.HotSearchDao;
import com.luguz.service.HotSearchService;
import com.luguz.util.RedisUtil;
import com.luguz.util.getHotSearchUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Map;

/**
 * @author Guz
 * @create 2022-03--01 21:03
 */
@Service
public class HotSearchServiceIMPL implements HotSearchService {
    @Autowired
    RedisUtil redisUtil;
    @Override
    public boolean storageHotSearch() {
        Map<String, ArrayList<HotSearchDao>> hotSearch = getHotSearchUtil.getHotSearch();
//        while(hotSearch == null && JSON.toJSONString(hotSearch) == "{}") hotSearch = getHotSearchUtil.getHotSearch();
//        System.out.println(hotSearch);
        System.out.println("storage任务开启 获取热搜数据存储");
        System.out.println(hotSearch);
        redisUtil.hset("luguz", "hotSearch",hotSearch);
        return true;
    }
    @Override
    public Map<String, ArrayList<HotSearchDao>> getHotSearch() {
        System.out.println(redisUtil.hget("luguz","hotSearch"));
        return (Map<String, ArrayList<HotSearchDao>>) redisUtil.hget("luguz","hotSearch");
    }
}
